/**
 * 
 */
package gisc.gov.vn.dev.projectX.workspace;

import javax.swing.JOptionPane;

import com.iver.andami.PluginServices;
import com.iver.cit.gvsig.fmap.drivers.DBException;
import com.iver.cit.gvsig.fmap.drivers.db.utils.SingleVectorialDBConnectionManager;

/**
 * @author HT
 *
 */
public class GiscConnectionManager implements IGiscConnectionManager {
	//------------//
	//Constructor //
	//------------//
	private String _dbName="";
	private Boolean success=false;
	public GiscConnectionManager()
	{
		
	}
	public GiscConnectionManager(String drvName, String port, String host,
			String dbName, String user, String pw, String conn_usr_name,
			boolean is_conn)
	{
		this._dbName=dbName;
		success=AddConnection(drvName, port, host, dbName, user, pw, conn_usr_name, is_conn);
	}
	
	protected void showConnectionErrorMessage(String _msg) {
        String msg = (_msg.length() > 300) ? "" : (": " + _msg);
        String title = "";
        JOptionPane.showMessageDialog(null, title + msg, title,
            JOptionPane.ERROR_MESSAGE);
    }
	
	/**
	 * implements IGiscConnectionManager
	 * @author HT
	 * 
	 */
	@Override
	public Boolean AddConnection(String drvName, String port, String host,
			String dbName, String user, String pw, String conn_usr_name,
			boolean is_conn) {
		// TODO Auto-generated method stub
		try
		{
			SingleVectorialDBConnectionManager.instance()
	        .getConnection(drvName, user, pw,
	conn_usr_name, host, port, dbName, is_conn);
			
			return true;
		}
		catch (DBException e) {
			// TODO: handle exception
			showConnectionErrorMessage(e.getMessage());
			return false;
		}
	}
	/* (non-Javadoc)
	 * @see gisc.gov.vn.dev.projectX.workspace.IGiscConnectionManager#GetDbName()
	 */
	@Override
	public String GetDbName() {
		// TODO Auto-generated method stub
		return this._dbName;
	}
	/* (non-Javadoc)
	 * @see gisc.gov.vn.dev.projectX.workspace.IGiscConnectionManager#Close()
	 */
	/**
	 * Chua tim duoc method dong ket noi
	 */
	@Override
	public Boolean Close() {
		// TODO Auto-generated method stub

		return null;
	}
	/* (non-Javadoc)
	 * @see gisc.gov.vn.dev.projectX.workspace.IGiscConnectionManager#IsSuccess()
	 */
	@Override
	public Boolean IsSuccess() {
		// TODO Auto-generated method stub
		return success;
	}
	


}
